package com.example.yrdev.ordering_system.Model;

import android.content.Context;

import com.example.yrdev.ordering_system.Database.DingHanDB;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

/**
 * Created by luke on 17/11/2016.
 */

public class CardRecord {

    public static final String DH_TABLE_NAME = "card_report";

    public  static final String DH_Card_TicketID = "Ticket_ID";
    public  static final String DH_Card_ID = "ID";
    public  static final String DH_Card_No = "No";
    public static final String DH_Card_Name = "Name";//会员姓名
    public  static final String DH_Card_UsageCount = "Usage_Count";
    public  static final String DH_Card_purchaseAmount = "Amount";
    public  static final String DH_Card_remain = "Remain";
    public  static final String DH_Card_discountRate = "Discount_Rate";
    public  static final String DH_Card_Date = "Date";
    public  static final String DH_Card_HttpDateTime = "HttpDateTime";
    public  static final String DH_Card_DeviceNo = "Device_No";
    public static final String DH_Card_Operator = "Operator";
    public  static final String DH_Card_ReportType = "Report_type";//1:充值,2:取款,3:退款,7:随机消费/定额消费,6:商品消费
    public  static final String DH_Card_RefundIndex = "Refund_index";//此交易退款标志,0：未退款，1：已退款
    public  static  final String DH_Card_uploadMark="Upload_Mark";


  public   static final String DH_CREATE_TABLE="CREATE TABLE " + DH_TABLE_NAME + "(  " +DH_Card_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +DH_Card_TicketID + " TEXT,"+ DH_Card_No + " TEXT,"
            + DH_Card_Name +" TEXT,"+DH_Card_UsageCount + " INTEGER," + DH_Card_purchaseAmount + " DOUBLE,"
            + DH_Card_remain + " DOUBLE," + DH_Card_discountRate + " TEXT," + DH_Card_Date + " TEXT,"+DH_Card_HttpDateTime + " TEXT," + DH_Card_DeviceNo + " TEXT," + DH_Card_Operator
            + " TEXT," + DH_Card_ReportType + " INTEGER," + DH_Card_RefundIndex+" INTEGER,"+ DH_Card_uploadMark+" INTEGER"+ ")";
    String ticketID;//发票号
    String CardNo;//卡号

    int id;

    int UsageCount=0;//次数

   Double PurchaseAmount=0.;//消费额

 Double Remain=0.;// 余额

    String DiscountRate="100%";//折扣比

    String cardName;//会员姓名

    String usageDate;//日期时间

    String DeviceNo="1";//机器号

    String Operator="0";//操作员

    String httpDateTime;

    int refundIndex=0;

    int payMode;//0 现金,1 信用卡,2 签单,3 会员卡,4 礼劵, 8 - 退货  会员卡,9 - 退货  现金

    int ReportType=1;//1:充值,2:取款,3:退款,7:随机消费/定额消费,6:商品消费
   private int uploadMark;


    public static boolean removeAllRecord(Context context,int recordType){

    return     DingHanDB.getInstance(context).removeAllReport(recordType);


    }

    public static ArrayList<CardRecord>getRecordListWithType(Context context,int recordType){

        return DingHanDB.getInstance(context).getCardReport("",recordType);

    }
    public static void changeCardReportUploadMark(Context context,CardRecord record){
        record.setUploadMark(1);
        DingHanDB.getInstance(context).changeCardReportUploadMark(record);

    }
    public String getTicketID() {

        return ticketID;
    }

    public String getCardNo() {
        return CardNo;
    }

    public int getUsageCount() {
        return UsageCount;
    }

    public Double getPurchaseAmount() {
        return PurchaseAmount;
    }

    public Double getRemain() {
        return Remain;
    }

    public String getDiscountRate() {
        return DiscountRate;
    }

    public String getHttpDateTime() {
        return httpDateTime;
    }

    public String getUsageDate() {

        if (usageDate==null){
            usageDate=getDate();

        }
//
        return usageDate;
    }

    public int getRefundIndex() {
        return refundIndex;
    }

    public String getDeviceNo() {
        return DeviceNo;
    }

    public String getOperator() {
        return Operator;
    }

    public int getReportType() {
        return ReportType;
    }

    public void setUsageCount(int usageCount) {
        UsageCount = usageCount;
    }

    public String getCardName() {
        return cardName;
    }

    public void setHttpDateTime(String httpDateTime) {
        this.httpDateTime = httpDateTime;
    }


    public CardRecord(String cardNo){
        CardNo=cardNo;

    }

    public void setId(int id) {
        this.id = id;
    }

    public void setCardName(String cardName) {
        this.cardName = cardName;
    }

    public void setTicketID(String ticketID) {
        this.ticketID = ticketID;
    }

    public void setReportType(int reportType) {
        ReportType = reportType;
    }

    public String getDate() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
        Date date = new Date();
        return dateFormat.format(date);

    }


    public int getId() {
        return id;
    }

    public int getUploadMark() {
        return uploadMark;
    }

    public void setOperator(String operator) {
        Operator = operator;
    }

    public void setDiscountRate(String discountRate) {
        DiscountRate = discountRate;
    }

    public void setRefundIndex(int refundIndex) {
        this.refundIndex = refundIndex;
    }


    public void setPayMode(int payMode) {
        this.payMode = payMode;
    }

    public void setUsageDate(String usageDate) {
        this.usageDate = usageDate;
    }

    public void setDeviceNo(String deviceNo) {
        DeviceNo = deviceNo;
    }

    public int getPayMode() {
        return payMode;
    }

    public void setPurchaseAmount(Double purchaseAmount) {
        PurchaseAmount = purchaseAmount;
    }

    public void setRemain(Double remain) {
        Remain = remain;
    }

    public void setUploadMark(int uploadMark) {
        this.uploadMark = uploadMark;
    }


}
